<?php
class qc_caf extends controller{

	function qc_caf()
	{
		parent::Controller();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->model('caf_model');
        $this->load->library(array('session','check_users'));
		$this->check_users->is_alive(); 
			
	}
  //to get batch card details for qc....
	function select_batchcardqc()
   {
    $this->load->helper('flexigrid');
    $user_ses = $this->session->userdata('userlogindetails');
    $displayform = '';
     
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
        $displayform .='<div id=dashboard ><span>Batch Card Details</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
        
          $batch = $this->caf_model->get_batch_qc_entry();
                   
          $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'idea_home/logout">Logout</a></div>';
          $displayform .= '<br/>';
        
          $displayform .='<table width=60% border=1 align=center>';
          $displayform .='<tr>';
          $displayform .='<td align=center>';
          $displayform .='<b>Sl No.</b>';
          $displayform .='</td>';
          $displayform .='<td align=center>';
          $displayform .='<b>Batch Details</b>';
          $displayform .='</td>';
          $displayform .='</tr>';
          $i=1;
          foreach ($batch->result_array() as $row)
          {
            $displayform .='<tr>';
            $displayform .='<td align=center>';
            $displayform .= $i;
            $displayform .='</td>';
            $displayform .='<td align=center>';
            $displayform .= '<a href="'.base_url().'qc_caf/set_batchnum/'.$row['batch_number'].'" id=batch_num >'.$row['batch_number'].'</a>';
            $displayform .='</td>';
            $displayform .='</tr>';
            $i++;
          }
          
          
          $displayform .='</table>';
        
          $data = array('formdisplay'=>$displayform,);  
          
          $this->template->write_view('header','header', $data, True);
          $this->template->write_view('content', 'other_general');
          $this->template->render();
          
          
          
    }
    else
    {
      echo "Forbidden to access!!!";
    }
      
  }
    
    function set_batchnum($batch=0)
    {
    $user_ses = $this->session->userdata('userlogindetails');    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
  
        $this->session->set_userdata('batch_num',$batch);
     
        redirect("qc_caf/qc_list"); 
    }
    else
    {
      echo "Forbidden to access!!!";
    }
  }
    
//this is to display all qc list....

	function qc_list()
	{
	  	
	  $user_ses = $this->session->userdata('userlogindetails');    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
      $this->load->helper('flexigrid');
  	
  		$displayform = '';
  		$displayform .='<div id=dashboard ><span>QC Data Entry</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a><img align=right src="'.base_url().'images/back.png" id="back"" alt="back" ONCLICK="history.go(-1)" /></div>';
      $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><input type="button" id="quick_qc" value="Quick QC" />&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div>';
  	
  		$displayform .= '<br/>';
  				
  		$displayform .= '<table id="flex1" style="display:none" border=0 align=left ></table>';
  		$colModel['id'] = array('ID',60,TRUE,'center',0);
  		$colModel['batch_mobilenum'] = array('Mobile Number',120,TRUE,'center',0);
  		$colModel['caf_customername'] = array('Customer Name',180,TRUE,'center',1);
  		$colModel['status'] = array('Status',92,TRUE,'center',1);
  		$gridParams = array(
  		'width' => '800',
  		'height' => 400,
  		'rp' => 15,
  		'rpOptions' => '[10,15,20,30]',
  		'pagestat' => 'Displaying:{from} to {to} of {total} items.',
  		'blockOpacity' => 0.5,
  		'title' => 'QC Data List',
  		'showTableToggleBtn' => true
  		);
  		
  		
  		$grid_js = build_grid_js('flex1',site_url("/ajax/qc_list"),$colModel,'caf_id','asc',$gridParams);
  		
  		$data['js_grid'] = $grid_js;
  		  		
  		$data = array('formdisplay'=>$displayform,'js_grid'=>$grid_js );	
      
      
      
  		$this->template->add_css('css/flexigrid/flexigrid.css');
  		$this->template->add_js('js/flexigride/jquery.pack.js');
  		$this->template->add_js('js/flexigride/flexigrid.pack.js');
  		$this->template->add_js('
  		$(window).load(function () {
        $("#quick_qc").focus();
      });
      
      $(document).ready(function()
      {
        $("#quick_qc").click(function()
        {
          var url = "'.base_url().'qc_caf/qc_data/1";    
                            
          window.location.href = url;
        });
      });
  		        
  		','embed');
      
  		//ends here....
  		$this->template->write_view('header','header', $data, True);
  		$this->template->write_view('content', 'general_flexigrid');
  		$this->template->render();
  	}
    else
    {
          echo "Forbidden to Access";
    }  
	}
	
 
  
	function qc_data($sl_num=1)
	{
	  $user_ses = $this->session->userdata('userlogindetails');    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    { 
       	
    		$caf_data = $this->caf_model->qc_cafdata($sl_num);
    		
    		$qc_data = $caf_data->result_array();	
		//	print_r($qc_data);exit;
         $displayform = '';
        if($qc_data)
        {
          
             
          	//for rejected forms separate action...
          	//start here....
          		$displayform .= '<div id=dialogform title="Reject Form">';
          		$displayform .= '<form action="'.base_url().'qc_caf/save_qc" method=post >';
          		$displayform .= '<input type=hidden name=caf_id value='.$qc_data[0]['caf_id'].' />';
          		
          		$displayform .= '<label>Reason to Reject</label>';
          		$displayform .= '<textarea name=rej_reason rows=6 cols=25 id=reason class="text ui-widget-content ui-corner-all"></textarea>';
          	
          		$displayform .= '<div align=right><input type=submit value=Reject name=Reject  /></div>';
          		
          		$displayform .= '</form>';
          		$displayform .= '</div>';
          	
          	//ends here....
          		$attr = array('id'=>'qc_form');
          		$displayform .= form_open('qc_caf/save_qc',$attr);		
          		$displayform .='<div id=dashboard ><span>QC Data Entry</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a></div>';
               $displayform .= '<span style="float:left;">Welcome '.$user_ses['user_name'].'</span><div id=logout><a href="'.base_url().'qc_caf/qc_list">View Remaining QC Details</a>&nbsp;<a href="'.base_url().'idea_home/logout">Logout</a></div>';
			   
          		$displayform .= '<div> &nbsp;</div>';
          		$displayform .= '<div id=div_entry >';
          		$displayform .= '<fieldset><legend>CAF Info</legend>';
          		
          		$displayform .='<table width=100% >';
		$displayform .='<tr>';
		$displayform .='<td><B>Batch No:</B><span id=batch_no style="color:#999999" >'.$qc_data[0]['batch_number'].'</span>';
		$displayform .= '<input type=hidden name=caf_id value='.$qc_data[0]['caf_id'].' />';
		$displayform .= '<input type=hidden name="batch_id" value="'.$qc_data[0]['batch_id'].'" />';
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>SL No:</b><input type="text" name="sl_num" id="sl_num" value='.$qc_data[0]['sl_num'].' size="2" /><input type="button" id="quick_entry" name=Quick value="Retrive"/>';
		
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>Mobil Num:</b>';
  		$displayform .= '<input type=text name=mobile_num size=10 value="'.$qc_data[0]['batch_mobilenum'].'" disabled=disabled />';
  		
		$displayform .='</td>';
		$displayform .='</tr>';
		list($date,$time) = explode(" ",$qc_data[0]['lastupdate']);
         list($yy,$mm,$dd) = explode("-",$date);
		 $date_num = $dd.'/'.$mm.'/'.$yy;
		$displayform .='<tr>';
		$displayform .='<td>';
		
		$displayform .= '<b>CAF Filed On:</b>'; 
  		
		$displayform .= '<input type=text name =filled_on_date id=filled_on_date size=10 value='.$date_num.' disabled=disabled /></span>';
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .= '<b>Retailer Name:</b><input type="text" name="retailer_name" value="'.$qc_data[0]['caf_retailername'].'" id="retailer_name" size=15 TABINDEX=1 />';
	   
		$displayform .='</td>';
		$displayform .='<td>';
		$displayform .='<b>Sim No:</b><input type="text" name=sim_no id="sim_no" TABINDEX=2 value="'.$qc_data[0]['sim_num'].'"	 /> ';
		$displayform .='</td>';
		$displayform .='</tr>';
		
		$displayform .='</table>';
			
          		$displayform .= '</fieldset>';
          		$displayform .= '<div id=personal1><fieldset><legend>Personal Details</legend>';
          		$displayform .= '<table align=left width=100% >';
          		$displayform .= '<tr><td colspan=6><span id=salutation> Salutation:';
          		$displayform .= '&nbsp;&nbsp;<select name=salutation>';
          		$displayform .= '<option value='.$qc_data[0]['caf_salutation'].'> '.$qc_data[0]['caf_salutation'].'.</option>';
          		$displayform .= '<option value=Mr> Mr.</option>';
          		$displayform .= '<option value=Mrs>Mrs.</option>';
          		$displayform .= '<option value=Ms>Ms.</option>';
          		$displayform .= '<option value=Dr>Dr.</option>';
          		$displayform .= '</select>';
          		$displayform .= '</span>';
          		$displayform .= '<span id=sex>Sex:';
          		$displayform .= '<select name=sex>';
          		$displayform .='<option value='.$qc_data[0]['caf_sex'].'>'.$qc_data[0]['caf_sex'].'</option>';		
          		$displayform .='<option value=M>M</option>';
          		$displayform .= '<option value=F>F</option></select></span>';
				 $displayform .= '<span id=martial >Marital:';
	      $displayform .= '&nbsp;<select name=marital >';
		  if($qc_data[0]['caf_marital_status']=='S')
		  {
		  	$displayform .= '<option value=S>Single</option>';
		  }
		  else
		  {
		  	$displayform .= '<option value=M>Married</option>';
		  }
	      $displayform .= '<option value=S>Single</option>';
	      $displayform .= '<option value=M>Married</option>';
	      $displayform .= '</select>';
	      $displayform .= '</span>';
          		$displayform .= '<span id=dob>DOB:';
          		list($yy,$mm,$dd) = explode("-",$qc_data[0]['caf_dob']);
          		
          		$displayform .= '<input type=text name =dob id=idob size=10 value="'.$dd.'/'.$mm.'/'.$yy.'" class="datepicker" /></span></td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr><td align=right>';
          		$displayform .= 'Customer Name:</td>';
          		$displayform .= '<td colspan=5><input type=text name=customer_name id=cust_name value="'.$qc_data[0]['caf_customername'].'"  size=45 /></td></tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Father Name:</td>';
          		$displayform .= '<td colspan=5><input type=text name=father_name value="'.$qc_data[0]['caf_fathersname'].'"  id=father_name size=45 /></td></tr>';
          		$displayform .= '<tr><td align=right>Nationality:</td>';
          		$displayform .= '<td><select name=nationality>';
          		$displayform .= '<option value='.$qc_data[0]['caf_nationality'].'>'.$qc_data[0]['caf_nationality'].'</option>';
          		$displayform .= '<option value=Indian>Indian</option>';
          		$displayform .= '<option value=Foreigner>Foreigner</option></select>';
          		$displayform .= '</td>';
          		$displayform .= '<td>Add Type:';
              $displayform .= '<select name=add_type>';
              $displayform .= '<option value="'.$qc_data[0]['caf_add_type'].'">'.$qc_data[0]['caf_add_type'].'</option>';
              $displayform .= '<option value="R">R</option>';
              $displayform .= '<option value="O">O</option>';
              $displayform .= '</select>';
              $displayform .= '</td>';
              
             
          		//$displayform .= '<td>&nbsp;&nbsp;</td>';
            //  $gen_name = $this->caf_model->fetch_state($qc_data[0]['caf_state']);
          	//	$name = $gen_name->result_array();
              $tate_name = $this->caf_model->fetch_state();
        
          		$displayform .= '</tr>';
          
          		$displayform .= '</table>';
          		$displayform .= '</fieldset></div>';
          		$displayform .= '<div id="personal2"><fieldset><legend>Personal Details</legend>';
              
          		$displayform .= '<table align=left width=50% >';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>POI Type:</td>';
          		$displayform .= '<td><select name="poi_type1">';
          		
          		//to fetch description...i tried to fetch from same above query but i didnt get because two different poi type.
          		$poi_desc1 = $this->caf_model->fetch_poi($qc_data[0]['caf_poitype1']);	
          		$poi_desc1_val = $poi_desc1->result_array();
              
          		$displayform .= '<option value='.$qc_data[0]['caf_poitype1'].'>'.$poi_desc1_val[0]['poi_desc'].'</option>';
          		
          		$poi_name = $this->caf_model->fetch_poi();
          		
          		foreach($poi_name ->result_array() as $row)
          		{
          			$displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
          		}	
          		$displayform .= '</select></td>';
          	
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>POI Num:</td>';
          		$displayform .= '<td><input type=text name=poi_num1 value="'.$qc_data[0]['caf_poidetails1'].'" id=poi_num1 size=30 /></td>';
         
          		$displayform .= '</tr>';
          		$displayform .= '</table>';
              $displayform .= '<table align=left width=50% >';
              $displayform .= '<tr>';
              $displayform .= '<td align=right>POA Type:</td>';
              $displayform .= '<td><select name="poi_type2">';
              $poi_desc2 = $this->caf_model->fetch_poi($qc_data[0]['caf_poitype2']);
              $poi_desc2_val = $poi_desc2->result_array();
              $displayform .= '<option value='.$qc_data[0]['caf_poitype2'].'>'.$poi_desc2_val[0]['poi_desc'].'</option>';
              foreach($poi_name ->result_array() as $row)
              {
                $displayform .= '<option value='.$row['poi_id'].'>'.$row['poi_desc'].'</option>';
              }
              
              $displayform .= '</select></td>';
              $displayform .= '</tr>';
              $displayform .= '<tr>';
              $displayform .= '<td align=right>POA Num:</td>';
              $displayform .= '<td><input type=text name=poi_num2 id=poi_num2 value="'.$qc_data[0]['caf_poidetails2'].'"  size=30 /></td>';
              $displayform .= '</tr>';
              $displayform .= '</table>';
              
          		$displayform .= '</fieldset></div>';
				
          		$displayform .= '<div>';
				$displayform .= '<table width=100%>';
				$displayform .= '<tr>';
				$displayform .= '<td width=50%>';
          		
          		$displayform .= '<fieldset><legend>Local Address</legend>';
          		$displayform .= '<table align=left width=100% >';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Address:</td>';
          		$displayform .= '<td><input type=text name=doc_addr_num id=doc_addr_num size=20 value="'.$qc_data[0]['caf_doc_address1'].'"  /></td>';
          		$displayform .= '</tr>'; 
          		
          		$displayform .= '<tr>';
          		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=doc_addr_cross id=doc_addr_cross value="'.$qc_data[0]['caf_doc_address2'].'"  />';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>State:</td>';
          		$displayform .= '<td align=left>';
          		$state_result = $this->caf_model->fetch_state($qc_data[0]['caf_doc_state']);
          		$doc_state = $state_result->result_array();
          		$displayform .= '<select name=doc_state style="width:200px;" >';
          		$displayform .= '<option value='.$qc_data[0]['caf_doc_state'].'>'.$doc_state[0]['state_name'].'</option>';
          		foreach($tate_name ->result_array() as $row)
          		{
          			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
          		}
          		$displayform .= '</select>';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align="right">City/District:</td><td>';
          		$city_name = $this->caf_model->fetch_city($qc_data[0]['caf_doc_city']);
          		$city = $city_name->result_array();
          		$displayform .= '<select name="doc_city" id="doc_city" style="width:200px;">';
          		$displayform .= '<option value="'.$city[0]['city_id'].'">'.$city[0]['city_name'].'</option>';
          		$all_cities = $this->caf_model->fetch_city();
          		foreach($all_cities->result_array() as $row)
          		{
          			$displayform .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
          		}
          		$displayform .= '</select>';	
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Area:</td>';
          		$displayform .= '<td>';
          		//to fetch area info...
          		$area_name = $this->caf_model->fetch_area($qc_data[0]['caf_doc_area']);
          		$area = $area_name->result_array();
          		$displayform .= '<select name="doc_area" id="doc_area" style="width:160px;">';
          		$displayform .= '<option value="'.$area[0]['area_id'].'">'.$area[0]['area_name'].'</option>';	
          		$all_areas = $this->caf_model->fetch_area();
          		foreach($all_areas->result_array() as $areas)
          		{
          				$displayform .= '<option value="'.$areas['area_id'].'">'.$areas['area_name'].'</option>';	
          		}
          		$displayform .= '</select>';
          		$displayform .='Pincode:<input type=text name=doc_pincode id=doc_pin size=6 value="'.$qc_data[0]['caf_doc_pincode'].'" /></td>';
          		$displayform .= '</tr>';
				 $displayform .= '<tr>';
			      $displayform .= '<td align="right">Phone1:';
			     
			      $displayform .= '</td>';
			      $displayform .= '<td>';
			      $displayform .= '<input type="text" name="loc_ph1" id="loc_ph1" size=10 value="'.$qc_data[0]['caf_doc_phone1'].'" />';
			      $displayform .= '&nbsp;Phone2:<input type="text" name="loc_ph2" id="loc_ph2" size=10 value="'.$qc_data[0]['caf_doc_phone2'].'" />';
			      $displayform .= '</td>';
			     
			     
			      $displayform .= '</tr>';
			       $displayform .= '<tr>';
			     
			       $displayform .= '<tr>';
			      $displayform .= '<td align="right">Cont Person:';
			     
			      $displayform .= '</td>';
			      $displayform .= '<td>';
			      $displayform .= '<input type="text" name="cont_person" id="cont_person" size=10 value="'.$qc_data[0]['cont_person'].'"/>';
			      $displayform .= '</td>';
			     
			      $displayform .= '</tr>';
          		$displayform .= '</table>';
          		$displayform .= '</fieldset>';
          		$displayform .= '</td>';
				
				$displayform .= '<td>';
				          		
          		$displayform .= '<fieldset><legend>Permanent Address</legend>';
          		$displayform .= '<table align=left>';
          		
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>&nbsp;</td>';
          		$displayform .= '<td>&nbsp;</td>';
          		$displayform .= '</tr>';
          		
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Address:</td>';
          		$displayform .= '<td><input type=text name=alt_addr_num value="'.$qc_data[0]['caf_alt_address1'].'" id=alt_num  /></td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td >&nbsp;</td><td align=left><input type=text name=alt_addr_cross id=alt_cross value="'.$qc_data[0]['caf_alt_address2'].'"  />';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
				$displayform .= '<tr>';
		  		$displayform .= '<td align=right>Country:</td>';
		  		$displayform .= '<td align=left>';
				if($qc_data[0]['caf_alt_country'] == 'India')
				{
						$displayform .= '<select name=country id=country>';
						$displayform .= '<option value=India>India</option>';
						$displayform .= '</select>';
				}
				else
				{
					$displayform .= '<input type=text name="country" value='.$qc_data[0]['caf_alt_country'].' />';
				}
				
		  		$displayform .= '</td>';
		  		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>State:</td>';
          		$displayform .= '<td align=left>';
          		$state_result = $this->caf_model->fetch_state($qc_data[0]['caf_alt_state']);
          		$doc_state = $state_result->result_array();
				if($qc_data[0]['caf_alt_country'] == 'India')
				{
	          		$displayform .= '<select name=alt_state  style="width:200px;" >';
	          		$displayform .= '<option value='.$qc_data[0]['caf_doc_state'].'>'.$doc_state[0]['state_name'].'</option>';
	          		foreach($tate_name ->result_array() as $row)
	          		{
	          			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
	          		}
	          		$displayform .= '</select>';
				}
				else
				{
					$displayform .= '<input type=text name="foreign_state" value="'.$qc_data[0]['caf_alt_foriegn_state'].'" />';
				}

          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>City/District:</td><td align=left>';
				
          		$alt_city = $this->caf_model->fetch_city($qc_data[0]['caf_alt_city']);
          		$alt_city_name = $alt_city->result_array();
				if($qc_data[0]['caf_alt_country'] == 'India')
				{
	          		$displayform .= '<select name=alt_city id="alt_city" style="width:200px;">';
	          		$displayform .= '<option value="'.$alt_city_name[0]['city_id'].'">'.$alt_city_name[0]['city_name'].'</option>';
          		
	          		foreach($all_cities->result_array() as $row)
	          		{
	          			$displayform .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
	          		}
	          		$displayform .= '</select>';		
				}
				else
				{
					$displayform .='<input type="text" name="foreign_city" value='.$qc_data[0]['caf_alt_foriegn_city'].' />';
				}
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Area:</td>';
          		$displayform .= '<td>';
          		$area_name = $this->caf_model->fetch_area($qc_data[0]['caf_alt_area']);
          		$alt_area = $area_name->result_array();	
				if($qc_data[0]['caf_alt_country'] == 'India')
				{
	          		$displayform .= '<select name=alt_area id="alt_area" style="width:160px;">';
	          		$displayform .= '<option value="'.$alt_area[0]['area_id'].'">'.$alt_area[0]['area_name'].'</option>';
	          		
	          		foreach($all_areas->result_array() as $areas)
	          		{
	          				$displayform .= '<option value="'.$areas['area_id'].'">'.$areas['area_name'].'</option>';	
	          		}
	           
	          		$displayform .= '</select>';
				}
				else
				{
					$displayform .='<input type="text" name="foreign_area" value='.$qc_data[0]['caf_alt_foriegn_area'].' />';
				}	
          		$displayform .= '&nbsp;Pincode:<input type=text name=alt_pincode id=alt_pin size=6 value="'.$qc_data[0]['caf_alt_pincode'].'"/></td>';
          		$displayform .= '</tr>';
          		$displayform .= '</table>';
          		$displayform .= '</fieldset>';
          		$displayform .= '</td>';
				$displayform .= '</tr>';
				$displayform .= '</table>';
          		$displayform .= '</div>';
				
				$displayform .= '<div>';
				$displayform .='<table width=100%>';
		$displayform .='<tr>';
		$displayform .='<td width=50%>';
		$displayform .= '<fieldset><legend>Local Refree Details</legend>';
  		$displayform .= '<table align=left >';
		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Ref Name:</td>';
  		$displayform .= '<td><input type=text name=ref_name value="'.$qc_data[0]['caf_referer_name'].'" id="ref_name" /></td>';
  		$displayform .= '</tr>';
		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Ref Phone:</td>';
  		$displayform .= '<td><input type=text name=ref_ph value="'.$qc_data[0]['caf_referer_phone'].'" id="ref_ph"  /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right>Address:</td>';
  		$displayform .= '<td><input type=text name=loc_addr_num value="'.$qc_data[0]['caf_referer_address1'].'"  id="loc_addr_num" /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
		
  
		$displayform .='</td>';
		$displayform .='<td >';
	
        
      
  		$displayform .= '<fieldset><legend style="color:blue;">Page Info</legend>';
  		$displayform .= '<table  width=100% >';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right width=20%>NOP:</td><td align=left width=80%><input type=text name="nop" value="'.$qc_data[0]['caf_nop'].'" id="nop" size=1 maxlength=2 /></td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		$displayform .= '<td align=right >BLD RGN:</td><td align=left><input type=text name="bld_reg" id="bld_reg" value="'.$qc_data[0]['caf_bld_reg'].'" size=4 />';
  		$displayform .= '</td>';
  		$displayform .= '</tr>';
  		$displayform .= '<tr>';
  		
  		$displayform .= '<tr>';
  		$displayform .= '<td colspan=2 align=center> <input type=submit id=submit_data value=Save "> &nbsp;&nbsp;<input type=reset value=Cancel "></td>';
  		$displayform .= '</tr>';
  		$displayform .= '</table>';
  		$displayform .= '</fieldset>';
  	
		$displayform .='</td>';
		$displayform .='</tr>';

		$displayform .='</table>';
		$displayform .= "<input type=hidden name=status value=approve id=approve  />";
				$displayform .= '</div>';
				$displayform .= form_close();
				
				$displayform .= '</div>';
				
				/*
				$displayform .= '<div style="width:50%;float:left;">';
          		$displayform .= '<fieldset><legend>Local Refree Details</legend>';
          		$displayform .= '<table align=left>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Address:</td>';
          		
          		
              $displayform .= '<td><input type=text name=loc_addr_num id="loc_addr_num" value="'.$qc_data[0]['caf_referer_address1'].'" /></td>';
            
          
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td >&nbsp;</td>';
             
              $displayform .='<td align=left><input type=text name=loc_addr_cross id="loc_addr_cross" value="'.$qc_data[0]['caf_referer_address2'].'" class="autobox"  />';  
          
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>State:</td>';
          		$displayform .= '<td align=left>';
          		$state_result = $this->caf_model->fetch_state($qc_data[0]['caf_referer_state']);
          		$doc_state = $state_result->result_array();
          		$displayform .= '<select name=loc_state style="width:200px;">';
              if(!$qc_data[0]['caf_referer_state'])
              {
                  $displayform .= '<option value=0>select state</option>';
              }
              else
              {
          		    $displayform .= '<option value='.$qc_data[0]['caf_doc_state'].'>'.$doc_state[0]['state_name'].'</option>';
              }
          		foreach($tate_name ->result_array() as $row)
          		{
          			$displayform .= '<option value='.$row['state_id'].'>'.$row['state_name'].'</option>';
          		}
          		$displayform .= '</select>';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>City/District:</td>';
          		
          		$displayform .= '<td>';
          		//for local city....
          		$loc = $this->caf_model->fetch_city($qc_data[0]['caf_referer_city']);
          		$loc_city = $loc->result_array();
          		$displayform .= '<select name=loc_city id="loc_city" style="width:200px;">';
                 if(!$qc_data[0]['caf_referer_city'])
                 {
                   $displayform .='<option value="0">select City</option>';
                 }
                 else
                  { 
              		  $displayform .= '<option value="'.$loc_city[0]['city_id'].'">'.$loc_city[0]['city_name'].'</option>';
                  }
              		foreach($all_cities->result_array() as $row)
              		{
              			$displayform .= '<option value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
              		}
             
          		$displayform .= '</select>';		
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td align=right>Area:</td><td align=left>';
          		$area_name = $this->caf_model->fetch_area($qc_data[0]['caf_referer_area']);
          		$loc_area = $area_name->result_array();
          		$displayform .= '<select name=loc_area id="loc_area" style="width:160px;" >';
              if(!$qc_data[0]['caf_referer_area'])
              {
                $displayform .= '<option value="0">Select Area</option>';
              }
              else
              {
          		  $displayform .= '<option value="'.$loc_area[0]['area_id'].'">'.$loc_area[0]['area_name'].'</option>';
          		}
          		foreach($all_areas->result_array() as $areas)
          		{
          				$displayform .= '<option value="'.$areas['area_id'].'">'.$areas['area_name'].'</option>';	
          		}
          		$displayform .= '</select>';	
          		$displayform .=	'Pincode:<input type=text name=loc_pincode id="loc_pin" value="'.$qc_data[0]['caf_referer_pincode'].'" size=6/>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
          		$displayform .= '</tr>';
          		$displayform .= '</table>';
          		$displayform .= '</fieldset>';
          		$displayform .= '</div>';
				
				$displayform .= '<div id=instructions >';
          		$displayform .= '<fieldset>';
          		$displayform .= '<table align=left  width=100%>';
          		$displayform .= '<tr><td colspan=2 align=center>';
          		$displayform .= "<input type=radio name=status value=approve id=approve checked=checked />Approve &nbsp;";
          	//	$displayform .= "<input type=radio name=status value=reject id=reject /> Reject &nbsp;";
          		$displayform .= '</td></tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td colspan=2>&nbsp;';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td colspan=2 >&nbsp;';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td colspan=2>&nbsp;';
          		$displayform .= '</td>';
          		$displayform .= '</tr>';
          		$displayform .= '<tr>';
          		$displayform .= '<td colspan=2 align=center><input type=submit id=submit_data value=Save "/>&nbsp;&nbsp;<input type=reset value=Cancel "/></td>';
          		$displayform .= '</tr>';
          		$displayform .= '</table>';
          		$displayform .= '</fieldset>';
          		$displayform .= '</div>';
				 * 
				 */
          		
          		
												
    	   }
          else
         {
           $displayform .= '<div id=dashboard ><span>QC Data Entry</span> <a href='.base_url().'/idea_home/general_dashboard ><img align=right src="'.base_url().'images/home.png" alt="home" /></a></div>';
           $displayform .= '<br/>';
           $displayform .= '<div style="float:center;">Data is not available to process!! </div>';
         }
    		$data = array('formdisplay'=>$displayform );
    
    		
    		
    		$this->template->add_js('js/ui/jquery.ui.datepicker.js');
    		$this->template->add_js('js/jquery.autobox.js');
    		
    		$this->template->add_js('js/ui/jquery.ui.position.js');
    		$this->template->add_js('js/ui/jquery.ui.autocomplete.js');
    		$this->template->add_js('js/caf/caf_validation.js');
			
        $this->template->add_js('
           $(document).ready(function(){
                                  $("#quick_check").click(function(){
                                  var sl_no = $("#sl_num").val();
                                  var url = "'.base_url().'qc_caf/qc_data/"+sl_no;    
                                
    
                                  window.location.href = url;
                                
                                  });
                                });
    		','embed');
    		$this->template->add_js('
    				$(function() {
    			$( ".datepicker" ).datepicker(			
    			{
    			dateFormat: "dd/mm/yy",
    			yearRange: "1900:2010",
    			changeMonth: true,
    			changeYear: true,
    			showOn: "button",
    			buttonImage: "'.base_url().'images/calendar.gif",
    			buttonImageOnly: true
    		
    		});
    		
    		});
    
    		','embed');
    		
    		
    		
    		$this->template->add_js('
    			$(document).ready(function(){
    	   		$(".check").click(function(){
    	   			});
    			});
    		','embed');
    		//for dialog window...
    		$this->template->add_js('js/ui/jquery.ui.mouse.js');
    		$this->template->add_js('js/ui/jquery.ui.draggable.js');
    		$this->template->add_js('js/ui/jquery.ui.position.js');
    		$this->template->add_js('js/ui/jquery.ui.resizable.js');
    		$this->template->add_js('js/ui/jquery.ui.dialog.js');
    		$this->template->add_js('js/ui/jquery.effects.core.js');
    		
    		$this->template->add_js('
    		$(function(){
    				$( "#dialogform" ).dialog({
    				autoOpen: false,
    				height: 270,
    				width: 350,
    				modal: true
    			
    			});
    			
    		
    			$("#reject").click(function(){
    				var scr = $("#reject").val();
    				
    				$("#dialogform").dialog("open");
    				
    				return false;
    				
    			});
    			
    			
    		});
    		','embed');
    		//ends here....
    		$this->template->write_view('header','header', $data, True);
    		$this->template->write_view('content', 'other_general');
    		$this->template->render();
	   }
    else
    {
      echo "Forbidden to access";
    }
  } 
	
	function save_qc()
	{
	  $user_ses = $this->session->userdata('userlogindetails');    
    if($user_ses['user_id'] && ($user_ses['user_group'] == 2))
    {
		    $this->caf_model->qc_caf_save();
       		 $sl = $_POST['sl_num']+1;
		    redirect('qc_caf/qc_data/'.$sl);
    }
    else
    {
       echo "Forbidden to access";
    }
		

	}
	
	
}


